# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Christopher O'Neill <milkytracker@chrisoneill.co.uk>
# Contributor: Maks Verver <maksverver@geocities.com>

pkgname=milkytracker
pkgver=1.03.00
pkgrel=3
pkgdesc='Music tracker inspired by Fast Tracker II'
arch=(loong64 x86_64)
url='https://milkytracker.titandemo.org/'
license=(GPL3)
depends=(alsa-lib lhasa rtmidi sdl2 zlib zziplib)
makedepends=(cmake jack ninja)
optdepends=('jack: JACK audio support')
# disable stripping, see: https://bugs.archlinux.org/task/30018
options=(!strip)
source=("$pkgname-$pkgver.tar.gz::https://github.com/milkytracker/MilkyTracker/archive/v$pkgver.tar.gz")
b2sums=('f14a7112de39748121933d242d89dc6efb71a73c3591fedb92785814e2edc788edfb6608e9237cdfed19ee7337d5920d0232eed5d85f692dbef5d4cb43a27cd0')

prepare() {
  mv MilkyTracker-$pkgver $pkgname-$pkgver
  # remove explicit use of C++98
  sed -e '/CMAKE_CXX_STANDARD/d' -e '/CMAKE_CXX_EXTENSIONS/d' \
    -i $pkgname-$pkgver/CMakeLists.txt
}

build() {
  cmake \
    -B build \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -G Ninja \
    -W nodev \
    -S $pkgname-$pkgver
  ninja -C build
}

package() {
  depends+=(libasound.so librtmidi.so)
  DESTDIR="$pkgdir" ninja install -C build
  cd $pkgname-$pkgver/resources
  install -Dm644 pictures/carton.png "$pkgdir/usr/share/pixmaps/$pkgname.png"
  install -Dm644 $pkgname.desktop -t "$pkgdir/usr/share/applications/"
  # also rename from .appdata to .appdata.xml
  install -Dm644 $pkgname.appdata "$pkgdir/usr/share/appdata/$pkgname.appdata.xml"
}
